package com.secneo.appshare.activities;

import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.widget.Toast;

import com.secneo.appshare.R;
import com.secneo.appshare.common.ActivityUtil;

public class CommonActivity extends Activity
{
	private Context ctx;
	private int closeSelfFlag=0;
	public void setContext(Context context)
	{
		ctx = context;
	}
	@Override
	protected void onPause() 
	{
		super.onPause();
		closeSelfFlag=0;
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) 
	{
		if (keyCode == KeyEvent.KEYCODE_BACK) 
		{
			closeSelfFlag=closeSelfFlag+1;
			if(closeSelfFlag==1)
			{
				Toast.makeText(this, this.getResources().getString(R.string.toast_close_self), Toast.LENGTH_SHORT).show();
			}else if(closeSelfFlag==2)
			{
				ActivityUtil.closeSelfApp(CommonActivity.this);
			}
		
			return true;
		} 
		else 
			return super.onKeyDown(keyCode, event);
	}
}
